const http = require('http');

function fn1() {
    console.log('fn1');
}
function fn2() {
    console.log('fn2');
}

http.createServer(function(request, response){
    console.log(request, response);
    switch(request.method) {
        case 'GET':
            try {
                fn1();
                switch(request.url) {
                    case '/api/1':
                        console.log(1);
                        break;
                    case '/api/2':
                        console.log(2);
                        break;
                }
                fn2();
            } catch (error) {
                console.log(error);
            }
            
            break;
        case 'POST':
            break;
    }

    response.writeHead(200, { 'Content-Type': 'text-plain' });
    response.end('Hello World\n');
}).listen(3000);